package com.qianyu.project.mapper.provider.cyy;

import com.qianyu.project.entity.Budget;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.Map;

public class DirectlyMapperProvider {

    public String getDirectlyList(Map<String,Object> map){
        return new SQL(){
            {
                SELECT("b.*,p.project_name,e.name");
                FROM("budget b,project_info p,emp e");
                WHERE("b.p_id=p.id");
                WHERE("b.e_id=e.id");
                if (!StringUtils.isEmpty(map.get("projectName"))){
                    WHERE("p.project_name='"+map.get("projectName")+"'");
                }
                if (!StringUtils.isEmpty(map.get("name"))){
                    WHERE("e.name='"+map.get("name")+"'");
                }
                if (!StringUtils.isEmpty(map.get("budgetName"))){
                    WHERE("b.budget_name like '%"+map.get("budgetName")+"%'");
                }
                if (!StringUtils.isEmpty(map.get("startcreateDate")) && !StringUtils.isEmpty(map.get("endcreateDate"))){
                    WHERE("b.create_date >= '"+map.get("startcreateDate")+"' and b.create_date<='"+map.get("endcreateDate")+"'");
                }

            }
        }.toString();
    }

    public String getDirectlyList1(Map<String,Object> map){
        return new SQL(){
            {
                SELECT("b.*,p.project_name,e.name");
                FROM("budget b,indirect i,project_info p,emp e");
                WHERE("b.i=i.b_id");
                WHERE("b.p_id=p.id");
                WHERE("b.e_id=e.id");
                if (!StringUtils.isEmpty(map.get("projectName"))){
                    WHERE("p.project_name='"+map.get("projectName")+"'");
                }
                if (!StringUtils.isEmpty(map.get("name"))){
                    WHERE("e.name='"+map.get("name")+"'");
                }
                if (!StringUtils.isEmpty(map.get("budgetName"))){
                    WHERE("b.budget_name like '%"+map.get("budgetName")+"%'");
                }
                if (!StringUtils.isEmpty(map.get("startcreateDate")) && !StringUtils.isEmpty(map.get("endcreateDate"))){
                    WHERE("b.create_date >= '"+map.get("startcreateDate")+"' and b.create_date<='"+map.get("endcreateDate")+"'");
                }

            }
        }.toString();
    }

    public String deleteDirectly(String id){
        return new SQL(){
            {
                DELETE_FROM("budget");
                WHERE("id=#{id}");
            }
        }.toString();
    }
}
